home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / SNAPSHOT.ASM < prev    next >
Assembly Source File  |  1986-06-05  |  15KB  |  284 lines

  1. INTERRUPTS      SEGMENT AT 0H   ;This is where the keyboard interrupt
  2.         ORG     9H*4            ;holds the address of its service routine
  3. KEYBOARD_INT    LABEL   DWORD
  4. INTERRUPTS      ENDS
  5.  
  6. SCREEN  SEGMENT AT 0B000H       ;A dummy segment to use as the
  7. SCREEN  ENDS                    ;Extra Segment
  8.  
  9. ROM_BIOS_DATA   SEGMENT AT 40H  ;BIOS statuses held here, also keyboard buffer
  10.  
  11.         ORG     1AH
  12.         HEAD DW      ?                  ;Unread chars go from Head to Tail
  13.         TAIL DW      ?
  14.         BUFFER       DW      16 DUP (?)         ;The buffer itself
  15.         BUFFER_END   LABEL   WORD
  16.  
  17. ROM_BIOS_DATA   ENDS
  18.  
  19. CODE_SEG        SEGMENT
  20.         ASSUME  CS:CODE_SEG
  21.         ORG     100H            ;ORG = 100H to make this into a .COM file
  22. FIRST:  JMP     LOAD_SNAPSHOT   ;First time through jump to initialize routine
  23.  
  24.         COPY_RIGHT DB  '(C) S. HOLZNER 1985'  ;An Ascii signature
  25. ;        KEYS   DW   310EH,2106H,1E01H,3002H,2E03H ;A Sample: ^N,^F,^A,^B,^C
  26.         KEYS   DW   5 DUP(0)
  27.         FLASHED    DB      0               ;Have we flashed a screenful? 1=yes
  28.         SNAPSHOT_OFFSET      DW      0          ;Chooses 1st 250 bytes or 2nd
  29.         SCREEN_SEG_OFFSET       DW      0       ;0 for mono, 8000H for graphics
  30.         IO_CHAR         DW      ?               ;Holds addr of Put or Get_Char
  31.         FILE_SIZE       DW      0               ;Read in this many bytes
  32.         OLD_KEYBOARD_INT        DD      ?       ;Location of old kbd interrupt
  33.         FILE            DB  'A.DAT',0           ;Asciiz. Changed to B.Dat, etc.
  34.         WS_FLAG         DB      0               ;<-- Set to 1 to strip WordStar
  35.         SNAPSHOT             DB      10000 DUP (32) ;Storage for screens
  36.  
  37. SNAP    PROC    NEAR            ;The keyboard interrupt will now come here.
  38.         ASSUME  CS:CODE_SEG
  39.         PUSH    AX              ;Save the used registers for good form
  40.         PUSH    BX
  41.         PUSH    CX
  42.         PUSH    DX
  43.         PUSH    DI
  44.         PUSH    SI
  45.         PUSH    DS
  46.         PUSH    ES
  47.         PUSHF                   ;First, call old keyboard interrupt
  48.         CALL    OLD_KEYBOARD_INT
  49.  
  50.         ASSUME  DS:ROM_BIOS_DATA        ;Examine the char just put in
  51.         MOV     BX,ROM_BIOS_DATA
  52.         MOV     DS,BX
  53.         MOV     BX,TAIL                 ;Point to current tail
  54.         CMP     BX,HEAD                 ;If at head, kbd int has deleted char
  55.         JE      IN                      ;So leave
  56.         SUB     BX,2                    ;Point to just read in character
  57.         CMP     BX,OFFSET BUFFER        ;Did we undershoot buffer?
  58.         JAE     NO_WRAP                 ;Nope
  59.         MOV     BX,OFFSET BUFFER_END    ;Yes -- move to buffer top
  60.         SUB     BX,2                    ;Point to just read in character
  61. NO_WRAP:MOV     DX,[BX]                 ;** Typed character in DX now **
  62.         LEA     SI,KEYS                 ;Point to Keys for search
  63.         CMP     FLASHED,1               ;Should we restore screen?
  64.         JE      RESTORE                 ;Yes, jump there
  65.         CMP     DX,CS:[SI]              ;Compare to first key (Store screen)
  66.         JE      STORE                   ;So Store
  67.         ADD     SI,2                    ;Point to next key
  68.         CMP     DX,CS:[SI]              ;Second key -- should we flash screen?
  69.         JE      FLASH                   ;Yes
  70.         MOV     CX,3                    ;No -- check for .Dat keys (A.Dat,etc)
  71.         MOV     SNAPSHOT_OFFSET,4000    ;Point to beginning of .Dats in memory
  72. TEST:   ADD     SI,2                    ;Increment to next key
  73.         CMP     DX,CS:[SI]              ;Is it right?
  74.         JE      DATS                    ;Yes, flash a .Dat file on screen
  75.         ADD     SNAPSHOT_OFFSET,2000    ;Point to next .Dat
  76.         LOOP    TEST                    ;And go back until all three are done
  77.         JMP     OUT                     ;No keys matched. Jump Out.
  78. STORE:  MOV     TAIL,BX                 ;Delete character from buffer
  79.         MOV     FLASHED,0               ;Switch Modes on Flashed
  80.         MOV     SNAPSHOT_OFFSET,0       ;Point to screen storage part of pad
  81.         LEA     AX,GET_CHAR             ;Make IO use Get_char so current screen
  82.         MOV     IO_CHAR,AX              ;is stored
  83.         CALL    IO                      ;Store Screen
  84. IN:     JMP     OUT                     ;Done here, let's go.
  85. FLASH:  MOV     TAIL,BX
  86.         MOV     FLASHED,1           ;Switch Modes, next key will restore screen
  87.         MOV     SNAPSHOT_OFFSET,2000    ;Point to screen storage part
  88.         LEA     AX,GET_CHAR             ;Make IO use Get_char so current screen
  89.         MOV     IO_CHAR,AX              ;is stored
  90.         CALL    IO                      ;Store Screen
  91.         MOV     SNAPSHOT_OFFSET,0       ;Use 1st 250 bytes of Snapshot memory
  92.         LEA     AX,PUT_CHAR             ;Make IO use Put-Char so it does
  93.         MOV     IO_CHAR,AX
  94.         CALL    IO                      ;Put result on screen
  95.         JMP     OUT                     ;Done here.
  96. RESTORE:
  97.         MOV     FLASHED,0               ;Restore screen from memory
  98.         MOV     TAIL,BX                 ;Delete character from buffer
  99.         MOV     SNAPSHOT_OFFSET,2000    ;Point to storage part of memory
  100.         LEA     AX,PUT_CHAR             ;Make IO call Put_Char as it scans
  101.         MOV     IO_CHAR,AX              ;over all locations in screen
  102.         CALL    IO                      ;Restore screen
  103.         JMP     OUT                     ;And leave
  104.  
  105. DATS:   MOV     TAIL,BX
  106.         MOV     FLASHED,1           ;Switch Modes, next key will restore screen
  107.         PUSH    SNAPSHOT_OFFSET         ;Save this while Offset set for storing
  108.         MOV     SNAPSHOT_OFFSET,2000    ;Point to screen storage part
  109.         LEA     AX,GET_CHAR             ;Make IO use Get_char so current screen
  110.         MOV     IO_CHAR,AX              ;is stored
  111.         CALL    IO                      ;Store Screen
  112.         POP     SNAPSHOT_OFFSET         ;Restore pointer to stored .Dat
  113.         LEA     AX,PUT_CHAR             ;Make IO use Put-Char so it does
  114.         MOV     IO_CHAR,AX
  115.         CALL    IO                      ;Put result on screen
  116.  
  117. OUT:    POP     ES                      ;Do the Pops of all registers.
  118.         POP     DS
  119.         POP     SI
  120.         POP     DI
  121.         POP     DX
  122.         POP     CX
  123.         POP     BX
  124.         POP     AX
  125.         IRET                    ;An interrupt needs an IRET
  126. SNAP    ENDP
  127.  
  128. GET_CHAR        PROC    NEAR    ;Gets a char from screen and advances position
  129.         PUSH    DX
  130.         MOV     SI,2            ;Loop twice, once for char, once for attribute
  131. G_WAIT_LOW:
  132.         MOV     AH,ES:[DI]      ;Do the move from the screen, one byte at a time
  133.         INC     DI              ;Move to next screen location
  134.         DEC     SI              ;Decrement loop counter
  135.         CMP     SI,0            ;Are we done?
  136.         JE      LEAVE           ;Yes
  137.         MOV     SNAPSHOT[BX],AH      ;No -- put char we got into snapshot
  138.         JMP     G_WAIT_LOW      ;Do it again
  139. LEAVE:  INC     BX              ;Update location
  140.         POP     DX
  141.         RET
  142. GET_CHAR        ENDP
  143.  
  144. PUT_CHAR        PROC    NEAR    ;Puts one char on screen and advances position
  145.         PUSH    DX
  146.         MOV     AH,SNAPSHOT[BX]      ;Get the char to be put onto the screen
  147.         MOV     SI,2            ;Loop twice, once for char, once for attribute
  148.         MOV     ES:[DI],AH      ;Move to screen, one byte at a time
  149.         ADD     DI,2
  150.         SUB     SI,2
  151.         INC     BX              ;Point to next char
  152.         POP     DX
  153.         RET                     ;Exeunt
  154. PUT_CHAR        ENDP
  155.  
  156. IO      PROC    NEAR           ;This scans over all screen positions
  157.         ASSUME  ES:SCREEN               ;Use screen as extra segment
  158.         MOV     BX,SCREEN
  159.         MOV     ES,BX
  160.  
  161.         MOV     DI,SCREEN_SEG_OFFSET    ;DI will be pointer to screen postion
  162.         MOV     BX,SNAPSHOT_OFFSET           ;BX will be location pointer
  163.         MOV     CX,25                   ;There will be 10 lines
  164. LINE_LOOP:
  165.